package test.enba.generator.generator.controller;

import com.enba.boot.core.base.Result;
import test.enba.generator.generator.service.IRoleMenuService;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import test.enba.generator.generator.entity.RoleMenu;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 
 * </p>
 *
 * @author 恩爸编程
 * @since 2025-01-19
 */
@Controller
@RequestMapping("/generator/roleMenu")
public class RoleMenuController {

  @Resource
  private IRoleMenuService roleMenuService;

  /**
  * 查询所有接口
  *
  * @return list
  */
  @GetMapping
  public Result<List<RoleMenu>> findAll() {
      return Result.success(roleMenuService.list());
  }

  /**
  * 根据id查询数据接口
  *
  * @param id id
  * @return result
  */
  @GetMapping("/{id}")
  public Result<RoleMenu> findOne(@PathVariable Integer id) {
      return Result.success(roleMenuService.getById(id));
  }

  /**
  * 分页查询接口
  *
  * @param pageNum nume
  * @param pageSize size
  * @return result
  */
  @GetMapping("/page")
  public Result<Page<RoleMenu>> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
      QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
      return Result.success(roleMenuService.page(new Page<>(pageNum, pageSize), queryWrapper));
  }

  /**
  * 新增和更新接口
  *
  * @param roleMenu roleMenu
  * @return result
  */
  @PostMapping
  public Result<Boolean> save(@RequestBody RoleMenu roleMenu) {
      return Result.success(roleMenuService.saveOrUpdate(roleMenu));
  }

  /**
  * 删除接口
  *
  * @param id id
  * @return result
  */
  @DeleteMapping("/{id}")
  public Result<Boolean> delete(@PathVariable Integer id) {
      return Result.success(roleMenuService.removeById(id));
  }

  /**
  * 批量删除接口
  *
  *
  * @param ids ids
  * @return result
  */
  @PostMapping("/del/batch")
  public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
      return Result.success(roleMenuService.removeByIds(ids));
   }
}
